package OnlineLibrary.WebService;

import java.util.ArrayList;

import BookStore.common.Book;
import OnlineLibrary.WebSite.mainManager;
import OnlineLibrary.managers.CatalogMgr;

/**
 * 
 * Webservice called by mobile application
 */
public class CatalogWebService {
	
	/**
	 * Get the catalog as a list of strings
	 * @return the catalog
	 */
	public String[] getCatalog() {
		CatalogMgr catalogMgr = mainManager.getCatalogMgr();
		ArrayList<Book> catalog = catalogMgr.mergeCatalogs();
		if (catalog == null)
			return new String[0];
		String[] res = new String[catalog.size()];
		int i = 0;
		for (Book b : catalog) {
			//translate the current book into a string where fields are separated by ';'
			String entry = b.isbn + ";" + b.title + ";" + b.author + ";"
					+ b.language + ";" + b.sell_price;
			res[i] = entry;
			i++;
		}
		return res;
	}
}
